Skip to content

Add memory accounting to exponential histogram library. #132580

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Aug 14, 2025

Conversation

JonasKunz
Copy link
Contributor

@JonasKunz JonasKunz commented Aug 8, 2025

Implements memory accounting (Accountable) and circuit breaker support for the exponential histogram library added in #131220. Just like the T-Digest library, the circuit breaker is abstracted away through an interface, so that no direct dependency on it is required for the lib.

This PR now defines for the ExponentialHistogramMerger that if the result is queried, the merger is cleared and the caller takes ownership of the returned histogram. Therefore the caller is then responsible for correctly calling close() on the returned histogram.

I was hesitant of doing it this way, because when implementing the ES|QL support this might cause unnecessary allocations:

E.g. for a query like | STATS PERCENTILE(MERGE(responseTime), 0.9) by service.name, TBUCKET(1m) it might be more efficient if we can reuse the ExponentialHistogramMerger across the aggregation groups. In this case this would mean merging all histograms for the first service.name, query the percentile and then continue with the next group. It would be ideal if the PERCENTILE could operate on a histogram instance "lent" from the merger, so that it can be reused then for the next group instead of requiring a new allocation.
However, if this is actually useful we can add this behaviour later when we get to the ES|QL implementation.

@JonasKunz JonasKunz added >non-issue :StorageEngine/Mapping The storage related side of mappings labels Aug 8, 2025
@JonasKunz JonasKunz marked this pull request as ready for review August 8, 2025 14:24
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-storage-engine (Team:StorageEngine)


import org.apache.lucene.util.RamUsageEstimator;

class RamEstimationUtil {
Copy link
Contributor

@kkrik-es kkrik-es Aug 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should these be part of RamUsageEstimator? This can happen in a follow-up, or separate PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice, but RamUsageEstimator is part of lucene-core. I don't know if Lucene folks would want this as part of their public API?
T-Digest btw also implements this methods itself, but I though it is not worth it to extract them in some shared libary.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. Yeah moving this to a shared util for use inside ES makes sense, you can follow-up on that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@martijnvg this was the utility we talked about in the standup.
One idea was to move it into libs:core, but that would imply that libs:core then needs to depend on lucene-core.

If you have a suggestion on a good place for this utility or think keeping it copied as-is it would be great to hear.

Copy link
Contributor

@kkrik-es kkrik-es left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice.

…onentialhistogram/ExponentialHistogramMerger.java

Co-authored-by: Kostas Krikellas <[email protected]>
@JonasKunz JonasKunz removed the request for review from martijnvg August 14, 2025 08:24
@JonasKunz JonasKunz merged commit 624f497 into elastic:main Aug 14, 2025
33 checks passed
@JonasKunz JonasKunz deleted the exp-histo-accounting branch August 14, 2025 14:16
joshua-adams-1 pushed a commit to joshua-adams-1/elasticsearch that referenced this pull request Aug 15, 2025
---------

Co-authored-by: elasticsearchmachine <[email protected]>
Co-authored-by: Kostas Krikellas <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants